package edu.mse.camel.client.chat.message;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

public class MessageList extends Observable implements IMessageList {

	private List<IMessage> messages;
	
	private static MessageList INSTANCE = new MessageList();

	public static MessageList getInstance() {
		return INSTANCE;
	}
	
	private MessageList(){
		messages = new ArrayList<IMessage>();
		
	}
	@Override
	public void addMessage(IMessage message) {
		messages.add(message);
		this.setChanged();
		notifyObservers(message);
	}

	@Override
	public List<IMessage> getMessages() {
		return messages;
	}

	@Override
	public void removeMessage(IMessage message) {
		messages.remove(message);
		this.setChanged();
		notifyObservers(message);
		
	}

	@Override
	public void updateMessage(IMessage message) {
		if (messages.contains(message)){
			messages.set(messages.indexOf(message), message);
			this.setChanged();
			notifyObservers(message);			
		}
	}
}
